#pragma once
#include <iostream>
#include <string>

#define Die(code) exit(code)
#define CONV(s) (struct sockaddr *)(s)

enum
{
    USAGE_ERR = 1,
    SOCKET_ERR,
    BIND_ERR,
    LISTEN_ERR
};

const int gdefaultsockfd = -1;
const int gbacklog = 8;

bool ParseOneLine(std::string &str, std::string *out, const std::string &sep)
{

    auto pos = str.find(sep);
    if (pos == std::string::npos)
    {
        return false;
    }
    *out = str.substr(0, pos);
    str = str.substr(pos + sep.size());
    return true;
}
bool SplitString(const std::string &line, std::string *key, std::string *value, const std::string &sep)
{
    //_method: GET
    auto pos = line.find(sep);
    if (pos == std::string::npos)   return false;
    *key = line.substr(0, pos);
    *value = line.substr(pos + sep.size());
    return true;
}